package com.pitaya.winwine.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.pitaya.framework.common.ErrorInfo;

@Entity
@Table(name = "tb_vintry")
public class Vintry implements Serializable {
	
	private static final long serialVersionUID = 5952036612276418141L;
	
	@Id @GeneratedValue
	private Integer id;
	
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
	@JoinColumn(name = "userId")
	private User user;
	@Column(insertable = false, updatable = false)
	private Integer userId;
	
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, optional = false)
	@JoinColumn(name = "wineId")
	private Wine wine;
	private Integer total;
	private Float marketPrice;
	private Float price;
	private Integer drinkingRange;
	private Date drinkingPeriod;
	private String remark;
	private Date editTime;
	
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "vintry")
	@OrderBy("editTime desc")
	private Set<VintryLog> vintryLogs;
	
	@Transient
	private Integer drinkingType;
	@Transient
	private Integer priceType;
	@Transient
	private ErrorInfo errorInfo;
	
	public Vintry() {}
	public Vintry(Wine wine) {
		this.setWine(wine);
	}
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public Integer userId() {
		return userId;
	}
	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	public Wine getWine() {
		return wine;
	}
	public void setWine(Wine wine) {
		this.wine = wine;
	}
	public Integer getTotal() {
		return total;
	}
	public void setTotal(Integer total) {
		this.total = total;
	}
	public Float getMarketPrice() {
		return marketPrice;
	}
	public void setMarketPrice(Float marketPrice) {
		this.marketPrice = marketPrice;
	}
	public Float getPrice() {
		return price;
	}
	public void setPrice(Float price) {
		this.price = price;
	}
	public Integer getDrinkingRange() {
		return drinkingRange;
	}
	public void setDrinkingRange(Integer drinkingRange) {
		this.drinkingRange = drinkingRange;
	}
	public Date getDrinkingPeriod() {
		return drinkingPeriod;
	}
	public void setDrinkingPeriod(Date drinkingPeriod) {
		this.drinkingPeriod = drinkingPeriod;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public Date getEditTime() {
		return editTime;
	}
	public void setEditTime(Date editTime) {
		this.editTime = editTime;
	}
	
	public Set<VintryLog> getVintryLogs() {
		return vintryLogs;
	}
	
	public void setVintryLogs(Set<VintryLog> vintryLogs) {
		this.vintryLogs = vintryLogs;
	}
	
	public void addVintryLog(VintryLog vintryLog) {
		vintryLog.setVintry(this);
		this.vintryLogs.add(vintryLog);
	}
	
	
	public Integer getDrinkingType() {
		return drinkingType;
	}
	public void setDrinkingType(Integer drinkingType) {
		this.drinkingType = drinkingType;
	}
	public Integer getPriceType() {
		return priceType;
	}
	public void setPriceType(Integer priceType) {
		this.priceType = priceType;
	}
	public ErrorInfo getErrorInfo() {
		return errorInfo;
	}
	public void setErrorInfo(ErrorInfo errorInfo) {
		this.errorInfo = errorInfo;
	}
}
